import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from 'path';

export default defineConfig({
  css: {
    devSourcemap: true,
    preprocessorOptions: {
      scss: {
        // 避免使用旧的 API
        charset: false,
        // 不使用 additionalData 避免出现编译错误
      }
    }
  },

  define: {
    'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
  },

  plugins: [vue()],

  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
  },

  server: {
    port: 5173,
    host: '0.0.0.0',
    proxy: {
      // '/oneapi': {
      //   target: "http://114.132.83.76:1699",
      //   changeOrigin: true,
      //   rewrite: (path) => path.replace(/^\/oneapi/, ''),
      //   ws: true
      // },
      '/oneapi': {
        // target: 'http://localhost:1699',
        target: 'http://114.132.83.76:1699',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/oneapi/, '')
      }
    }
  },

  envPrefix: ['VITE_'],
  build: {
    target: 'esnext',
    sourcemap: true,
  },
});
